Conditions | 5 |
Paths | 3 |
Total Lines | 52 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | const Response = require('../util/response') |
||
8 | detail: async function (ctx) { |
||
9 | let templateId = ctx.params.templateId |
||
10 | |||
11 | let templateInfo = { |
||
12 | 'id': templateId, |
||
13 | 'image': 'http://tools.miaoke.tech/images/card/bg' + templateId + '.png', |
||
14 | } |
||
15 | |||
16 | switch (templateId) { |
||
17 | case '1': |
||
18 | templateInfo.avatar = { |
||
19 | 'width': '6.6', |
||
20 | 'height': '6.6', |
||
21 | 'marginTop': '3.9' |
||
22 | } |
||
23 | templateInfo.textarea = { |
||
24 | 'marginTop': '2.8', |
||
25 | 'color': '#fff', |
||
26 | 'family': '' |
||
27 | } |
||
28 | break |
||
29 | case '2': |
||
30 | templateInfo.avatar = { |
||
31 | 'width': '6.6', |
||
32 | 'height': '6.6', |
||
33 | 'marginTop': '5' |
||
34 | } |
||
35 | templateInfo.textarea = { |
||
36 | 'marginTop': '2.8', |
||
37 | 'color': '#fff', |
||
38 | 'family': '' |
||
39 | } |
||
40 | break |
||
41 | case '3': |
||
42 | templateInfo.avatar = { |
||
43 | 'width': '7', |
||
44 | 'height': '7', |
||
45 | 'marginTop': '4.4' |
||
46 | } |
||
47 | templateInfo.textarea = { |
||
48 | 'marginTop': '2.8', |
||
49 | 'color': '#fff', |
||
50 | 'family': '' |
||
51 | } |
||
52 | break |
||
53 | default: |
||
54 | throw new ApiError('common.notExist', '模板ID') |
||
55 | break |
||
56 | } |
||
57 | |||
58 | return Response.output(ctx, templateInfo) |
||
59 | }, |
||
60 | |||
62 | } |